# -*- coding = utf-8 -*-
# @Time    : 2025/4/2 上午9:12
# @Author  : yqk
# @File    : test.py
# @Software: PyCharm

import pyautogui
import time
# 导入selenium库中的webdriver模块
from selenium import webdriver
# 导入chrome浏览器的服务配置类
from selenium.webdriver.chrome.service import Service
# 导入chrome浏览器的选项配置类
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
# def get():
#     # 获取当前屏幕分辨率
#     screenWidth, screenHeight = pyautogui.size()
#     print(f"Screen resolution: {screenWidth}x{screenHeight}")
#
#     # 获取当前缩放比例
#     scale_factor = pyautogui.screenshot().size[0] / screenWidth # Screen resolution: 2560x1600 Scale factor: 1.0
#     print(f"Scale factor: {scale_factor}")
def press():
    pic_addr = r'D:\python-code\chaojiying_Python\douban2.png'
    time.sleep(2)
    loc = pyautogui.locateOnScreen(pic_addr, confidence=0.7)
    print(loc)

def check():
    screenshot = pyautogui.screenshot()
    screenshot.save('screenshot.png')
def login():
    # 配置chrome浏览器的服务路径
    service = Service(executable_path='D:\python-code\chromedriver-win64\chromedriver.exe')
    # 创建chrome浏览器的选项配置实例
    options = Options()
    # 设置调试器地址，以便连接到已有的chrome浏览器实例
    options.debugger_address = '127.0.0.1:8888'
    # 初始化webdriver实例，指定chrome服务和选项配置
    browser = webdriver.Chrome(service=service, options=options)
    # 通过webdriver实例访问指定的URL
    browser.get('http://www.douban.com')

    iframe = browser.find_element(By.XPATH,'//*[@id="anony-reg-new"]/div/div[1]/iframe')
    browser.switch_to.frame(iframe)

    browser.find_element(By.XPATH,'/html/body/div[1]/div[1]/ul[1]/li[2]').click()
    time.sleep(2)

    browser.find_element(By.XPATH,'//*[@id="password"]').send_keys('1334623')
    time.sleep(2)
    browser.find_element(By.XPATH,'//*[@id="username"]').send_keys('dczcd')
    time.sleep(2)
    # browser.find_element(By.XPATH,'/html/body/div[1]/div[2]/div[1]/div[5]/a').click()

    browser.switch_to.default_content()  # 退回·到访问iframe标签外的元素
    time.sleep(1)
if __name__ == '__main__':
    # get()
    login()
    press()
    # check()